**********************
* Suplementary tests *
**********************

set more off

* Bol's local path:
local path /Users/damienbol/Dropbox/Documents/Recherche/Peer-reviewed articles/regret strategic voting/Submitting JPE/

* Setting the phi paramater
***************************

use "`path'/regret.dta", clear

* Big regret

foreach var of varlist _t0-_t10 {

replace phi=0+`var'
replace psi=1-`var'

replace utility_party1=phi*(Q17A-pref_other1) if Q17A!=pref_top1 & Q17A!=pref_top2
replace utility_party1=phi*(Q17A-pref_other1) + psi*(close2*(Q17A-pref_top2)) if Q17A==pref_top1
replace utility_party1=phi*(Q17A-pref_other1) + psi*(close2*(Q17A-pref_top1)) if Q17A==pref_top2

replace utility_party2=phi*(Q17B-pref_other2) if Q17B!=pref_top1 & Q17B!=pref_top2
replace utility_party2=phi*(Q17B-pref_other2) + psi*(close2*(Q17B-pref_top2)) if Q17B==pref_top1
replace utility_party2=phi*(Q17B-pref_other2) + psi*(close2*(Q17B-pref_top1)) if Q17B==pref_top2

replace utility_party3=phi*(Q17C-pref_other3) if Q17C!=pref_top1 & Q17C!=pref_top2
replace utility_party3=phi*(Q17C-pref_other3) + psi*(close2*(Q17C-pref_top2)) if Q17C==pref_top1
replace utility_party3=phi*(Q17C-pref_other3) + psi*(close2*(Q17C-pref_top1)) if Q17C==pref_top2

replace utility_party4=phi*(Q17D-pref_other4) if Q17D!=pref_top1 & Q17D!=pref_top2 & Qc_fed==1
replace utility_party4=phi*(Q17D-pref_other4) + psi*(close2*(Q17D-pref_top2)) if Q17D==pref_top1 & Qc_fed==1
replace utility_party4=phi*(Q17D-pref_other4) + psi*(close2*(Q17D-pref_top1)) if Q17D==pref_top2 & Qc_fed==1

replace utility_party5=phi*(Q17E-pref_other5) if Q17E!=pref_top1 & Q17E!=pref_top2
replace utility_party5=phi*(Q17E-pref_other5) + psi*(close2*(Q17E-pref_top2)) if Q17E==pref_top1
replace utility_party5=phi*(Q17E-pref_other5) + psi*(close2*(Q17E-pref_top1)) if Q17E==pref_top2

replace utility_vote=utility_party1 if vote_post==1
replace utility_vote=utility_party2 if vote_post==2
replace utility_vote=utility_party3 if vote_post==3
replace utility_vote=utility_party4 if vote_post==4
replace utility_vote=utility_party5 if vote_post==5

replace utility_w=max(utility_party1, utility_party2, utility_party3, utility_party5) if Qc_fed==0
replace utility_w=max(utility_party1, utility_party2, utility_party3, utility_party4, utility_party5) if Qc_fed==1

replace utility_diff`var'=utility_w-utility_vote

reg b_regret utility_diff`var' age gend univ dissatis ambivalence exp_good i.vote_post Ont_fed Qc_fed

gen coef`var'=_b[utility_diff]
gen se`var'=_se[utility_diff]
gen lb`var'=coef`var'-(1.96*se`var')
gen ub`var'=coef`var'+(1.96*se`var')
}


keep if _n==1
keep coef_t* lb_t* ub_t* respid
reshape long coef_t lb_t ub_t, i(respid) j(t)  
lab var t "Weight given to expressive utility ({&phi})"

replace t=t*10
line coef_t t, lw(thick) xlabel(0(10)100) ylabel(0(.02)0.14) ytitle("Coefficient of utility difference") scheme(s2mono) graphregion(color(white)) title("Big regret") xline(60, lpattern(sdash)) legend(off) || line ub_t t, lp(dash) legend(off) || line lb_t t, lp(dash) legend(off)
graph save "bigregret.gph", replace


* Small regret

use "`path'/regret.dta", clear


foreach var of varlist _t0-_t10 {

replace phi=0+`var'
replace psi=1-`var'

replace utility_party1=phi*(Q17A-pref_other1) if Q17A!=pref_top1 & Q17A!=pref_top2
replace utility_party1=phi*(Q17A-pref_other1) + psi*(close2*(Q17A-pref_top2)) if Q17A==pref_top1
replace utility_party1=phi*(Q17A-pref_other1) + psi*(close2*(Q17A-pref_top1)) if Q17A==pref_top2

replace utility_party2=phi*(Q17B-pref_other2) if Q17B!=pref_top1 & Q17B!=pref_top2
replace utility_party2=phi*(Q17B-pref_other2) + psi*(close2*(Q17B-pref_top2)) if Q17B==pref_top1
replace utility_party2=phi*(Q17B-pref_other2) + psi*(close2*(Q17B-pref_top1)) if Q17B==pref_top2

replace utility_party3=phi*(Q17C-pref_other3) if Q17C!=pref_top1 & Q17C!=pref_top2
replace utility_party3=phi*(Q17C-pref_other3) + psi*(close2*(Q17C-pref_top2)) if Q17C==pref_top1
replace utility_party3=phi*(Q17C-pref_other3) + psi*(close2*(Q17C-pref_top1)) if Q17C==pref_top2

replace utility_party4=phi*(Q17D-pref_other4) if Q17D!=pref_top1 & Q17D!=pref_top2 & Qc_fed==1
replace utility_party4=phi*(Q17D-pref_other4) + psi*(close2*(Q17D-pref_top2)) if Q17D==pref_top1 & Qc_fed==1
replace utility_party4=phi*(Q17D-pref_other4) + psi*(close2*(Q17D-pref_top1)) if Q17D==pref_top2 & Qc_fed==1

replace utility_party5=phi*(Q17E-pref_other5) if Q17E!=pref_top1 & Q17E!=pref_top2
replace utility_party5=phi*(Q17E-pref_other5) + psi*(close2*(Q17E-pref_top2)) if Q17E==pref_top1
replace utility_party5=phi*(Q17E-pref_other5) + psi*(close2*(Q17E-pref_top1)) if Q17E==pref_top2

replace utility_vote=utility_party1 if vote_post==1
replace utility_vote=utility_party2 if vote_post==2
replace utility_vote=utility_party3 if vote_post==3
replace utility_vote=utility_party4 if vote_post==4
replace utility_vote=utility_party5 if vote_post==5

replace utility_w=max(utility_party1, utility_party2, utility_party3, utility_party5) if Qc_fed==0
replace utility_w=max(utility_party1, utility_party2, utility_party3, utility_party4, utility_party5) if Qc_fed==1

replace utility_diff`var'=utility_w-utility_vote

reg s_regret utility_diff`var' age gend univ dissatis ambivalence exp_good i.vote_post Ont_fed Qc_fed

gen coef`var'=_b[utility_diff]
gen se`var'=_se[utility_diff]
gen lb`var'=coef`var'-(1.96*se`var')
gen ub`var'=coef`var'+(1.96*se`var')
}


keep if _n==1
keep coef_t* lb_t* ub_t* respid
reshape long coef_t lb_t ub_t, i(respid) j(t)  
lab var t "Weight given to expressive utility ({&phi})"

replace t=t*10
line coef_t t, lw(thick) xlabel(0(10)100) ylabel(0(.02).16) ytitle("Coefficient of utility difference") scheme(s2mono) graphregion(color(white)) title("Small regret") xline(60, lpattern(sdash)) legend(off) || line ub_t t, lp(dash) legend(off) || line lb_t t, lp(dash) legend(off)
graph save "smallregret.gph", replace


* Linear

use "`path'/regret.dta", clear


foreach var of varlist _t0-_t10 {

replace phi=0+`var'
replace psi=1-`var'

replace utility_party1=phi*(Q17A-pref_other1) if Q17A!=pref_top1 & Q17A!=pref_top2
replace utility_party1=phi*(Q17A-pref_other1) + psi*(close*(Q17A-pref_top2)) if Q17A==pref_top1
replace utility_party1=phi*(Q17A-pref_other1) + psi*(close*(Q17A-pref_top1)) if Q17A==pref_top2

replace utility_party2=phi*(Q17B-pref_other2) if Q17B!=pref_top1 & Q17B!=pref_top2
replace utility_party2=phi*(Q17B-pref_other2) + psi*(close*(Q17B-pref_top2)) if Q17B==pref_top1
replace utility_party2=phi*(Q17B-pref_other2) + psi*(close*(Q17B-pref_top1)) if Q17B==pref_top2

replace utility_party3=phi*(Q17C-pref_other3) if Q17C!=pref_top1 & Q17C!=pref_top2
replace utility_party3=phi*(Q17C-pref_other3) + psi*(close*(Q17C-pref_top2)) if Q17C==pref_top1
replace utility_party3=phi*(Q17C-pref_other3) + psi*(close*(Q17C-pref_top1)) if Q17C==pref_top2

replace utility_party4=phi*(Q17D-pref_other4) if Q17D!=pref_top1 & Q17D!=pref_top2 & Qc_fed==1
replace utility_party4=phi*(Q17D-pref_other4) + psi*(close*(Q17D-pref_top2)) if Q17D==pref_top1 & Qc_fed==1
replace utility_party4=phi*(Q17D-pref_other4) + psi*(close*(Q17D-pref_top1)) if Q17D==pref_top2 & Qc_fed==1

replace utility_party5=phi*(Q17E-pref_other5) if Q17E!=pref_top1 & Q17E!=pref_top2
replace utility_party5=phi*(Q17E-pref_other5) + psi*(close*(Q17E-pref_top2)) if Q17E==pref_top1
replace utility_party5=phi*(Q17E-pref_other5) + psi*(close*(Q17E-pref_top1)) if Q17E==pref_top2

replace utility_vote=utility_party1 if vote_post==1
replace utility_vote=utility_party2 if vote_post==2
replace utility_vote=utility_party3 if vote_post==3
replace utility_vote=utility_party4 if vote_post==4
replace utility_vote=utility_party5 if vote_post==5

replace utility_w=max(utility_party1, utility_party2, utility_party3, utility_party5) if Qc_fed==0
replace utility_w=max(utility_party1, utility_party2, utility_party3, utility_party4, utility_party5) if Qc_fed==1

replace utility_diff`var'=utility_w-utility_vote

reg regret_inv utility_diff`var' age gend univ dissatis ambivalence exp_good i.vote_post Ont_fed Qc_fed

gen coef`var'=_b[utility_diff]
gen se`var'=_se[utility_diff]
gen lb`var'=coef`var'-(1.96*se`var')
gen ub`var'=coef`var'+(1.96*se`var')
}


keep if _n==1
keep coef_t* lb_t* ub_t* respid
reshape long coef_t lb_t ub_t, i(respid) j(t)  
lab var t "Weight given to expressive utility ({&phi})"

replace t=t*10
line coef_t t, lw(thick) xlabel(0(10)100) ylabel(0(.02).16) ytitle("Coefficient of utility difference") scheme(s2mono) graphregion(color(white)) title("Linear closeness") xline(60, lpattern(sdash)) legend(off) || line ub_t t, lp(dash) legend(off) || line lb_t t, lp(dash) legend(off)
graph save "linear.gph", replace

* Positive

use "`path'/regret.dta", clear


foreach var of varlist _t0-_t10 {

replace phi=0+`var'
replace psi=1-`var'

replace utility_party1=phi*(Q17A-pref_other1) if Q17A!=pref_top1 & Q17A!=pref_top2
replace utility_party1=phi*(Q17A-pref_other1) + psi*(close*(Q17A-pref_top2)) if Q17A==pref_top1
replace utility_party1=phi*(Q17A-pref_other1) + psi*(close*(Q17A-pref_top1)) if Q17A==pref_top2

replace utility_party2=phi*(Q17B-pref_other2) if Q17B!=pref_top1 & Q17B!=pref_top2
replace utility_party2=phi*(Q17B-pref_other2) + psi*(close*(Q17B-pref_top2)) if Q17B==pref_top1
replace utility_party2=phi*(Q17B-pref_other2) + psi*(close*(Q17B-pref_top1)) if Q17B==pref_top2

replace utility_party3=phi*(Q17C-pref_other3) if Q17C!=pref_top1 & Q17C!=pref_top2
replace utility_party3=phi*(Q17C-pref_other3) + psi*(close*(Q17C-pref_top2)) if Q17C==pref_top1
replace utility_party3=phi*(Q17C-pref_other3) + psi*(close*(Q17C-pref_top1)) if Q17C==pref_top2

replace utility_party4=phi*(Q17D-pref_other4) if Q17D!=pref_top1 & Q17D!=pref_top2 & Qc_fed==1
replace utility_party4=phi*(Q17D-pref_other4) + psi*(close*(Q17D-pref_top2)) if Q17D==pref_top1 & Qc_fed==1
replace utility_party4=phi*(Q17D-pref_other4) + psi*(close*(Q17D-pref_top1)) if Q17D==pref_top2 & Qc_fed==1

replace utility_party5=phi*(Q17E-pref_other5) if Q17E!=pref_top1 & Q17E!=pref_top2
replace utility_party5=phi*(Q17E-pref_other5) + psi*(close*(Q17E-pref_top2)) if Q17E==pref_top1
replace utility_party5=phi*(Q17E-pref_other5) + psi*(close*(Q17E-pref_top1)) if Q17E==pref_top2

replace utility_vote=utility_party1 if vote_post==1
replace utility_vote=utility_party2 if vote_post==2
replace utility_vote=utility_party3 if vote_post==3
replace utility_vote=utility_party4 if vote_post==4
replace utility_vote=utility_party5 if vote_post==5

replace utility_w=max(utility_party1, utility_party2, utility_party3, utility_party5) if Qc_fed==0
replace utility_w=max(utility_party1, utility_party2, utility_party3, utility_party4, utility_party5) if Qc_fed==1

replace utility_diff`var'=utility_w-utility_vote

reg regret_inv utility_diff`var' age gend univ dissatis ambivalence exp_good i.vote_post Ont_fed Qc_fed if utility_vote>=0

gen coef`var'=_b[utility_diff]
gen se`var'=_se[utility_diff]
gen lb`var'=coef`var'-(1.96*se`var')
gen ub`var'=coef`var'+(1.96*se`var')
}


keep if _n==1
keep coef_t* lb_t* ub_t* respid
reshape long coef_t lb_t ub_t, i(respid) j(t)  
lab var t "Weight given to expressive utility ({&phi})"

replace t=t*10
line coef_t t, lw(thick) xlabel(0(10)100) ylabel(0(.02).16) ytitle("Coefficient of utility difference") scheme(s2mono) graphregion(color(white)) title("No negative utility") xline(60, lpattern(sdash)) legend(off) || line ub_t t, lp(dash) legend(off) || line lb_t t, lp(dash) legend(off)
graph save "positive.gph", replace


* High knwoledge

use "`path'/regret.dta", replace

gen knowl=0
replace knowl=knowl+1 if PQ3_1==1
replace knowl=knowl+1 if PQ3_2==2
replace knowl=knowl+1 if PQ3_3==3
replace knowl=knowl/3

foreach var of varlist _t0-_t10 {

replace phi=0+`var'
replace psi=1-`var'

replace utility_party1=phi*(Q17A-pref_other1) if Q17A!=pref_top1 & Q17A!=pref_top2
replace utility_party1=phi*(Q17A-pref_other1) + psi*(close2*(Q17A-pref_top2)) if Q17A==pref_top1
replace utility_party1=phi*(Q17A-pref_other1) + psi*(close2*(Q17A-pref_top1)) if Q17A==pref_top2

replace utility_party2=phi*(Q17B-pref_other2) if Q17B!=pref_top1 & Q17B!=pref_top2
replace utility_party2=phi*(Q17B-pref_other2) + psi*(close2*(Q17B-pref_top2)) if Q17B==pref_top1
replace utility_party2=phi*(Q17B-pref_other2) + psi*(close2*(Q17B-pref_top1)) if Q17B==pref_top2

replace utility_party3=phi*(Q17C-pref_other3) if Q17C!=pref_top1 & Q17C!=pref_top2
replace utility_party3=phi*(Q17C-pref_other3) + psi*(close2*(Q17C-pref_top2)) if Q17C==pref_top1
replace utility_party3=phi*(Q17C-pref_other3) + psi*(close2*(Q17C-pref_top1)) if Q17C==pref_top2

replace utility_party4=phi*(Q17D-pref_other4) if Q17D!=pref_top1 & Q17D!=pref_top2 & Qc_fed==1
replace utility_party4=phi*(Q17D-pref_other4) + psi*(close2*(Q17D-pref_top2)) if Q17D==pref_top1 & Qc_fed==1
replace utility_party4=phi*(Q17D-pref_other4) + psi*(close2*(Q17D-pref_top1)) if Q17D==pref_top2 & Qc_fed==1

replace utility_party5=phi*(Q17E-pref_other5) if Q17E!=pref_top1 & Q17E!=pref_top2
replace utility_party5=phi*(Q17E-pref_other5) + psi*(close2*(Q17E-pref_top2)) if Q17E==pref_top1
replace utility_party5=phi*(Q17E-pref_other5) + psi*(close2*(Q17E-pref_top1)) if Q17E==pref_top2

replace utility_vote=utility_party1 if vote_post==1
replace utility_vote=utility_party2 if vote_post==2
replace utility_vote=utility_party3 if vote_post==3
replace utility_vote=utility_party4 if vote_post==4
replace utility_vote=utility_party5 if vote_post==5

replace utility_w=max(utility_party1, utility_party2, utility_party3, utility_party5) if Qc_fed==0
replace utility_w=max(utility_party1, utility_party2, utility_party3, utility_party4, utility_party5) if Qc_fed==1

replace utility_diff`var'=utility_w-utility_vote

reg regret_inv utility_diff`var' age gend univ dissatis ambivalence exp_good i.vote_post Ont_fed Qc_fed if knowl==1

gen coef`var'=_b[utility_diff]
gen se`var'=_se[utility_diff]
gen lb`var'=coef`var'-(1.96*se`var')
gen ub`var'=coef`var'+(1.96*se`var')
}

keep if _n==1
keep coef_t* lb_t* ub_t* respid
reshape long coef_t lb_t ub_t, i(respid) j(t)  
lab var t "Weight given to expressive utility ({&phi})"

replace t=t*10
line coef_t t, lw(thick) xlabel(0(10)100) ylabel(0(.02).16) ytitle("Coefficient of utility difference") scheme(s2mono) graphregion(color(white)) title("High knowledge") xline(70, lpattern(sdash)) legend(off) || line ub_t t, lp(dash) legend(off) || line lb_t t, lp(dash) legend(off)
graph save "highknow.gph", replace

* Low knowledge

use "`path'/regret.dta", replace

gen knowl=0
replace knowl=knowl+1 if PQ3_1==1
replace knowl=knowl+1 if PQ3_2==2
replace knowl=knowl+1 if PQ3_3==3
replace knowl=knowl/3

foreach var of varlist _t0-_t10 {

replace phi=0+`var'
replace psi=1-`var'

replace utility_party1=phi*(Q17A-pref_other1) if Q17A!=pref_top1 & Q17A!=pref_top2
replace utility_party1=phi*(Q17A-pref_other1) + psi*(close2*(Q17A-pref_top2)) if Q17A==pref_top1
replace utility_party1=phi*(Q17A-pref_other1) + psi*(close2*(Q17A-pref_top1)) if Q17A==pref_top2

replace utility_party2=phi*(Q17B-pref_other2) if Q17B!=pref_top1 & Q17B!=pref_top2
replace utility_party2=phi*(Q17B-pref_other2) + psi*(close2*(Q17B-pref_top2)) if Q17B==pref_top1
replace utility_party2=phi*(Q17B-pref_other2) + psi*(close2*(Q17B-pref_top1)) if Q17B==pref_top2

replace utility_party3=phi*(Q17C-pref_other3) if Q17C!=pref_top1 & Q17C!=pref_top2
replace utility_party3=phi*(Q17C-pref_other3) + psi*(close2*(Q17C-pref_top2)) if Q17C==pref_top1
replace utility_party3=phi*(Q17C-pref_other3) + psi*(close2*(Q17C-pref_top1)) if Q17C==pref_top2

replace utility_party4=phi*(Q17D-pref_other4) if Q17D!=pref_top1 & Q17D!=pref_top2 & Qc_fed==1
replace utility_party4=phi*(Q17D-pref_other4) + psi*(close2*(Q17D-pref_top2)) if Q17D==pref_top1 & Qc_fed==1
replace utility_party4=phi*(Q17D-pref_other4) + psi*(close2*(Q17D-pref_top1)) if Q17D==pref_top2 & Qc_fed==1

replace utility_party5=phi*(Q17E-pref_other5) if Q17E!=pref_top1 & Q17E!=pref_top2
replace utility_party5=phi*(Q17E-pref_other5) + psi*(close2*(Q17E-pref_top2)) if Q17E==pref_top1
replace utility_party5=phi*(Q17E-pref_other5) + psi*(close2*(Q17E-pref_top1)) if Q17E==pref_top2

replace utility_vote=utility_party1 if vote_post==1
replace utility_vote=utility_party2 if vote_post==2
replace utility_vote=utility_party3 if vote_post==3
replace utility_vote=utility_party4 if vote_post==4
replace utility_vote=utility_party5 if vote_post==5

replace utility_w=max(utility_party1, utility_party2, utility_party3, utility_party5) if Qc_fed==0
replace utility_w=max(utility_party1, utility_party2, utility_party3, utility_party4, utility_party5) if Qc_fed==1

replace utility_diff`var'=(utility_w-utility_vote)

reg regret_inv utility_diff`var' age gend univ dissatis ambivalence exp_good i.vote_post Ont_fed Qc_fed if knowl!=1

gen coef`var'=_b[utility_diff]
gen se`var'=_se[utility_diff]
gen lb`var'=coef`var'-(1.96*se`var')
gen ub`var'=coef`var'+(1.96*se`var')
}


keep if _n==1
keep coef_t* lb_t* ub_t* respid
reshape long coef_t lb_t ub_t, i(respid) j(t)  
lab var t "Weight given to expressive utility ({&phi})"

replace t=t*10
line coef_t t, lw(thick) xlabel(0(10)100) ylabel(0(.02).16) ytitle("Coefficient of utility difference") scheme(s2mono) graphregion(color(white)) title("Low knowledge") xline(60, lpattern(sdash)) legend(off) || line ub_t t, lp(dash) legend(off) || line lb_t t, lp(dash) legend(off)
graph save "lowknow.gph", replace


* Clear margin

use "`path'/regret.dta", replace

gen gap=top2-top3

gen gap2_3=0
replace gap2_3=1 if gap>0.1


foreach var of varlist _t0-_t10 {

replace phi=0+`var'
replace psi=1-`var'

replace utility_party1=phi*(Q17A-pref_other1) if Q17A!=pref_top1 & Q17A!=pref_top2
replace utility_party1=phi*(Q17A-pref_other1) + psi*(close2*(Q17A-pref_top2)) if Q17A==pref_top1
replace utility_party1=phi*(Q17A-pref_other1) + psi*(close2*(Q17A-pref_top1)) if Q17A==pref_top2

replace utility_party2=phi*(Q17B-pref_other2) if Q17B!=pref_top1 & Q17B!=pref_top2
replace utility_party2=phi*(Q17B-pref_other2) + psi*(close2*(Q17B-pref_top2)) if Q17B==pref_top1
replace utility_party2=phi*(Q17B-pref_other2) + psi*(close2*(Q17B-pref_top1)) if Q17B==pref_top2

replace utility_party3=phi*(Q17C-pref_other3) if Q17C!=pref_top1 & Q17C!=pref_top2
replace utility_party3=phi*(Q17C-pref_other3) + psi*(close2*(Q17C-pref_top2)) if Q17C==pref_top1
replace utility_party3=phi*(Q17C-pref_other3) + psi*(close2*(Q17C-pref_top1)) if Q17C==pref_top2

replace utility_party4=phi*(Q17D-pref_other4) if Q17D!=pref_top1 & Q17D!=pref_top2 & Qc_fed==1
replace utility_party4=phi*(Q17D-pref_other4) + psi*(close2*(Q17D-pref_top2)) if Q17D==pref_top1 & Qc_fed==1
replace utility_party4=phi*(Q17D-pref_other4) + psi*(close2*(Q17D-pref_top1)) if Q17D==pref_top2 & Qc_fed==1

replace utility_party5=phi*(Q17E-pref_other5) if Q17E!=pref_top1 & Q17E!=pref_top2
replace utility_party5=phi*(Q17E-pref_other5) + psi*(close2*(Q17E-pref_top2)) if Q17E==pref_top1
replace utility_party5=phi*(Q17E-pref_other5) + psi*(close2*(Q17E-pref_top1)) if Q17E==pref_top2

replace utility_vote=utility_party1 if vote_post==1
replace utility_vote=utility_party2 if vote_post==2
replace utility_vote=utility_party3 if vote_post==3
replace utility_vote=utility_party4 if vote_post==4
replace utility_vote=utility_party5 if vote_post==5

replace utility_w=max(utility_party1, utility_party2, utility_party3, utility_party5) if Qc_fed==0
replace utility_w=max(utility_party1, utility_party2, utility_party3, utility_party4, utility_party5) if Qc_fed==1

replace utility_diff`var'=(utility_w-utility_vote)

reg regret_inv utility_diff`var' age gend univ dissatis ambivalence exp_good i.vote_post Ont_fed Qc_fed if gap2_3==1

gen coef`var'=_b[utility_diff]
gen se`var'=_se[utility_diff]
gen lb`var'=coef`var'-(1.96*se`var')
gen ub`var'=coef`var'+(1.96*se`var')
}


keep if _n==1
keep coef_t* lb_t* ub_t* respid
reshape long coef_t lb_t ub_t, i(respid) j(t)  
lab var coef_t "Coefficient of utility difference" 
lab var t "Weight given to expressive utility ({&phi})"

replace t=t*10
line coef_t t, lw(thick) xlabel(0(10)100) ylabel(0(.02).16) ytitle("Coefficient of utility difference") scheme(s2mono) graphregion(color(white)) title("Clear margin") xline(60, lpattern(sdash)) legend(off) || line ub_t t, lp(dash) legend(off) || line lb_t t, lp(dash) legend(off)
graph save "gap.gph", replace

* Small margin

use "`path'/regret.dta", replace

gen gap=top2-top3

gen gap2_3=0
replace gap2_3=1 if gap>0.1


foreach var of varlist _t0-_t10 {

replace phi=0+`var'
replace psi=1-`var'

replace utility_party1=phi*(Q17A-pref_other1) if Q17A!=pref_top1 & Q17A!=pref_top2
replace utility_party1=phi*(Q17A-pref_other1) + psi*(close2*(Q17A-pref_top2)) if Q17A==pref_top1
replace utility_party1=phi*(Q17A-pref_other1) + psi*(close2*(Q17A-pref_top1)) if Q17A==pref_top2

replace utility_party2=phi*(Q17B-pref_other2) if Q17B!=pref_top1 & Q17B!=pref_top2
replace utility_party2=phi*(Q17B-pref_other2) + psi*(close2*(Q17B-pref_top2)) if Q17B==pref_top1
replace utility_party2=phi*(Q17B-pref_other2) + psi*(close2*(Q17B-pref_top1)) if Q17B==pref_top2

replace utility_party3=phi*(Q17C-pref_other3) if Q17C!=pref_top1 & Q17C!=pref_top2
replace utility_party3=phi*(Q17C-pref_other3) + psi*(close2*(Q17C-pref_top2)) if Q17C==pref_top1
replace utility_party3=phi*(Q17C-pref_other3) + psi*(close2*(Q17C-pref_top1)) if Q17C==pref_top2

replace utility_party4=phi*(Q17D-pref_other4) if Q17D!=pref_top1 & Q17D!=pref_top2 & Qc_fed==1
replace utility_party4=phi*(Q17D-pref_other4) + psi*(close2*(Q17D-pref_top2)) if Q17D==pref_top1 & Qc_fed==1
replace utility_party4=phi*(Q17D-pref_other4) + psi*(close2*(Q17D-pref_top1)) if Q17D==pref_top2 & Qc_fed==1

replace utility_party5=phi*(Q17E-pref_other5) if Q17E!=pref_top1 & Q17E!=pref_top2
replace utility_party5=phi*(Q17E-pref_other5) + psi*(close2*(Q17E-pref_top2)) if Q17E==pref_top1
replace utility_party5=phi*(Q17E-pref_other5) + psi*(close2*(Q17E-pref_top1)) if Q17E==pref_top2

replace utility_vote=utility_party1 if vote_post==1
replace utility_vote=utility_party2 if vote_post==2
replace utility_vote=utility_party3 if vote_post==3
replace utility_vote=utility_party4 if vote_post==4
replace utility_vote=utility_party5 if vote_post==5

replace utility_w=max(utility_party1, utility_party2, utility_party3, utility_party5) if Qc_fed==0
replace utility_w=max(utility_party1, utility_party2, utility_party3, utility_party4, utility_party5) if Qc_fed==1

replace utility_diff`var'=(utility_w-utility_vote)

reg regret_inv utility_diff`var' age gend univ dissatis ambivalence exp_good i.vote_post Ont_fed Qc_fed if gap2_3==0

gen coef`var'=_b[utility_diff]
gen se`var'=_se[utility_diff]
gen lb`var'=coef`var'-(1.96*se`var')
gen ub`var'=coef`var'+(1.96*se`var')
}


keep if _n==1
keep coef_t* lb_t* ub_t* respid
reshape long coef_t lb_t ub_t, i(respid) j(t)  
lab var coef_t "Coefficient of utility difference" 
lab var t "Weight given to expressive utility ({&phi})"

replace t=t*10
line coef_t t, lw(thick) xlabel(0(10)100) ylabel(0(.02).16) ytitle("Coefficient of utility difference") scheme(s2mono) graphregion(color(white)) title("Small margin") xline(60, lpattern(sdash)) legend(off) || line ub_t t, lp(dash) legend(off) || line lb_t t, lp(dash) legend(off)
graph save "nogap.gph", replace

* Figures
**********

graph combine "bigregret.gph" "smallregret.gph" "linear.gph" "positive.gph", cols(2) graphregion(color(white))
graph combine "highknow.gph" "lowknow.gph" "gap.gph" "nogap.gph", cols(2) graphregion(color(white))

